<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('images', function (Blueprint $table) {
            $table->id();
            $table->string('url'); // 图片 URL
            $table->string('path'); // 图片存储路径
            $table->unsignedBigInteger('article_id')->nullable(); // 关联文章 ID
            $table->unsignedBigInteger('user_id'); // 上传者 ID
            $table->enum('type', ['cover', 'content']); // 图片类型：封面或内容图片
            $table->enum('status', ['temporary', 'permanent'])->default('temporary'); // 状态：临时或正式
            $table->timestamps();
        
            $table->foreign('article_id')->references('id')->on('articles')->onDelete('set null');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->index('status');
            $table->index('article_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('images');
    }
};
